package com.example.simplejson4android.clazz;


import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

public class VideoQueryInfo {
	private String code; // 01 失败 00 成功
	private String message; // 返回信息
	private long total; // 总记录数
	private long count; // 拉取的记录数
	private String next_record; // 拉取列表的后一条记录
	private ArrayList<VideosInfo> videos = new ArrayList<VideosInfo>();

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public String getNext_record() {
		return next_record;
	}

	public void setNext_record(String next_record) {
		this.next_record = next_record;
	}

	public ArrayList<VideosInfo> getVideos() {
		return videos;
	}

	public void setVideos(ArrayList<VideosInfo> videos) {
		this.videos = videos;
	}

	public void parseJson(JSONObject object) {
		try {
			if (null != object) {
				if (object.has("code")) {
					this.code = object.optString("code");
					this.message = object.optString("message");
					this.next_record = object.optString("next_record");
					if (object.has("videos")) {
						VideosInfo videosInfo = new VideosInfo();
						JSONArray array = object.optJSONArray("videos");
						for (int k = 0; k < array.length(); k++) {
							JSONObject jsonObject = array.optJSONObject(k);
							if (jsonObject.has("video")) {
								JSONObject videoObject = jsonObject
										.optJSONObject("video");
								VideoInfo videoInfo = new VideoInfo();
								if (videoObject.has("videoId")) {
									videoInfo.setVideoId(videoObject
											.optString("videoId"));
								}
								if (videoObject.has("videoName")) {
									videoInfo.setVideoName(videoObject
											.optString("videoName"));
								}
								if (videoObject.has("name")) {
									videoInfo.setName(videoObject
											.optString("name"));
								}
								if (videoObject.has("videoUrl")) {
									videoInfo.setVideoUrl(videoObject
											.optString("videoUrl"));
								}
								if (videoObject.has("posterUrl")) {
									videoInfo.setPosterUrl(videoObject
											.optString("posterUrl"));
								}
								if (videoObject.has("filmType")) {
									videoInfo.setFilmType(videoObject
											.optString("filmType"));
								}
								if (videoObject.has("createTime")) {
									videoInfo.setCreateTime(videoObject
											.optString("createTime"));
								}
								if (videoObject.has("loveCount")) {
									videoInfo.setLoveCount(videoObject
											.optLong("loveCount"));
								}
								if (videoObject.has("commentCount")) {
									videoInfo.setCommentCount(videoObject
											.optInt("commentCount"));
								}
								if (videoObject.has("playCount")) {
									videoInfo.setPlayCount(videoObject
											.optLong("playCount"));
								}
								if (videoObject.has("favorite")) {
									videoInfo.setFavorite(videoObject
											.optString("favorite"));
								}
								if (videoObject.has("love")) {
									videoInfo.setLove(videoObject
											.optString("love"));
								}
								if (videoObject.has("isNew")) {
									videoInfo.setIsNew(videoObject
											.optString("isNew"));
								}
								if (videoObject.has("showTime")) {
									videoInfo.setShowTime(videoObject
											.optString("showTime"));
								}
								if (videoObject.has("director")) {
									videoInfo.setDirector(videoObject
											.optString("director"));
								}
								if (videoObject.has("protagonist")) {
									videoInfo.setProtagonist(videoObject
											.optString("protagonist"));
								}
								if (videoObject.has("intro")) {
									videoInfo.setIntro(videoObject
											.optString("intro"));
								}
								if (videoObject.has("source")) {
									videoInfo.setSource(videoObject
											.optString("source"));
								}
								if (videoObject.has("tag")) {
									JSONArray videoArray = videoObject.optJSONArray("tag");
									ArrayList<String> list =  new ArrayList<String>();
									for (int i = 0; i < videoArray.length(); i++) {
										list.add((String) videoArray.get(i));
									}
									videoInfo.setTag(list);
								}
								videosInfo.setVideo(videoInfo);
							}

							if (jsonObject.has("user")) {
								JSONObject userObject = jsonObject
										.optJSONObject("user");
								UserInfo userInfo = new UserInfo();
								if (userObject.has("userId")) {
									userInfo.setUserId(userObject
											.optString("userId"));
								}
								if (userObject.has("userName")) {
									userInfo.setUserName(userObject
											.optString("userName"));
								}
								if (userObject.has("gender")) {
									userInfo.setGender(userObject
											.optString("gender"));
								}
								if (userObject.has("avatar")) {
									userInfo.setAvatar(userObject
											.optString("avatar"));
								}
								if (userObject.has("following")) {
									userInfo.setFollowing(userObject
											.optString("following"));
								}
								if (userObject.has("followMe")) {
									userInfo.setFollowMe(userObject
											.optString("followMe"));
								}
								if (userObject.has("fansNum")) {
									userInfo.setFansNum(userObject
											.optInt("fansNum"));
								}
								if (userObject.has("loveNum")) {
									userInfo.setLoveNum(userObject
											.optInt("loveNum"));
								}
								videosInfo.setUser(userInfo);
							}
							this.videos.add(videosInfo);
						}

					}
				}
			}
		} catch (Exception e) {
e.printStackTrace();
		}
	}
}

